<template>
	<div class="page-wrap">
		<div class="page-content p-0">
			<div class="page-column p-0">
				<div class="page-form p-x-0">
					<el-form
						:model="ruleForm"
						:rules="rules"
						label-position="left"
						label-width="154px"
						ref="form"
						label-suffix="："
					>
						<el-row>
							<el-col :span="24">
								<el-form-item label="湿沉降线型因子" prop="WDCWASH1Num">
									<el-input
										:disabled="this.senstivity_Data.WDCWASH2Num>0"
										size="medium"
										class="mediumForm"
										@input="addWDCWASH1Num"
										v-model.number="ruleForm.WDCWASH1Num"
									>
										<template slot="append">套</template>
									</el-input>
								</el-form-item>

								<el-tabs class="m-20" v-model="activeName" type="card" @tab-click="handleClick">
									<el-tab-pane
										:label="item.index"
										:name="item.index"
										v-for="(item,index) in ruleForm.WDCWASH1List"
										:key="index"
									>
										<el-form-item
											label-width="0px"
											label
											:prop="'WDCWASH1List.'+index+'.WDCWASH1001' "
											:rules="rules.WDCWASH1001"
										>
											<el-input
												size="medium"
												class="mediumForm"
												oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,5})?).*$/g, '$1')"
												v-model="item.WDCWASH1001"
											></el-input>
										</el-form-item>
									</el-tab-pane>
								</el-tabs>

								<el-form-item label="湿沉降指数因子" prop="WDCWASH2Num">
									<el-input
										:disabled="this.senstivity_Data.WDCWASH1Num>0"
										size="medium"
										class="mediumForm"
										@input="addWDCWASH2Num"
										v-model.number="ruleForm.WDCWASH2Num"
									>
										<template slot="append">套</template>
									</el-input>
								</el-form-item>
								<el-tabs class="m-20" v-model="activeName2" type="card" @tab-click="handleClick">
									<el-tab-pane
										:label="item.index"
										:name="item.index"
										v-for="(item,index) in ruleForm.WDCWASH2List"
										:key="index"
									>
										<el-form-item
											label-width="0px"
											label
											:prop="'WDCWASH2List.'+index+'.WDCWASH2001' "
											:rules="rules.WDCWASH2001"
										>
											<el-input
												size="medium"
												class="mediumForm"
												oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,5})?).*$/g, '$1')"
												v-model="item.WDCWASH2001"
											></el-input>
										</el-form-item>
									</el-tab-pane>
								</el-tabs>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="bottom-btn">
					<el-button
						type="primary"
						:disabled="this.senstivity_Data.WDCWASH1Num>0 || this.senstivity_Data.WDCWASH2Num>0"
						:loading="loading"
						@click="submitFun"
					>下一步</el-button>
					<el-button
						type="primary"
						v-if="this.senstivity_Data.WDCWASH1Num>0 || this.senstivity_Data.WDCWASH2Num>0"
						:loading="loading"
						@click="tijiao"
					>提 交</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import selectPara from "@/components/selectPara"
import commCheckbox from "@/components/commCheckbox"
import ImageCropper from "@/components/ImageCropper"
import FixBottomButton from "@/components/FixBottomButton"
import ueditor from "@/components/ueditor"
import textLength from "@/components/common/comp/textLength"
import { commPara } from "@/mixins/mixins"
import { mapState } from "vuex"
import Axios from "axios"
import { dome, selecttext } from "@/utils/verify.js"

export default {
	name: "aboutUs",
	props: {},
	mixins: [commPara],
	components: {
		selectPara,
		ImageCropper,
		textLength,
		commCheckbox,
		FixBottomButton,
		ueditor,
	},
	computed: {
		...mapState({
			senstivity_Data: (state) => state.token.senstivity_Data,
			basic_Data: (state) => state.token.basic_Data,
		}),
	},

	data() {
		var CHEVACST001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1000.0) {
				callback(new Error("输入范围为[0.0，1000.0]"))
			} else {
				callback()
			}
		}
		var CHRELCST001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1000.1) {
				callback(new Error("输入范围为[0.0，1000.1]"))
			} else {
				callback()
			}
		}

		return {
			activeTab: "2",
			activeName: "1",
			activeName2: "1",
			ruleForm: {
				WDCWASH1Num: "0",
				WDCWASH2Num: "0",
				WDCWASH1List: [],
				WDCWASH2List: [],
			},
			rules: {
				WDCWASH1001: [
					{
						validator: dome(0.0, 1.0),
						trigger: ["change", "blur"],
					},
				],
				WDCWASH2001: [
					{
						validator: dome(0.0, 1.0),
						trigger: ["change", "blur"],
					},
				],
			},

			loading: false,
		}
	},
	computed: {
		...mapState({
			senstivity_Data: (state) => state.token.senstivity_Data,
		}),
	},
	created() {
		this.queryDetail()
	},
	methods: {
		setData() {
			this.ruleForm.WDCWASH1Num = this.senstivity_Data.WDCWASH1001.length
			if (this.ruleForm.WDCWASH1Num > 0) {
				this.ruleForm.WDCWASH1List = []
				for (
					let index = 0;
					index < parseInt(this.ruleForm.WDCWASH1Num);
					index++
				) {
					let n = index + 1
					this.ruleForm.WDCWASH1List.push({
						index: n.toString(),
						WDCWASH1001: this.senstivity_Data.WDCWASH1001[index],
					})
				}
				let tempdata = JSON.parse(JSON.stringify(this.senstivity_Data))
				tempdata.WDCWASH1Num = this.ruleForm.WDCWASH1Num
				this.$store.dispatch("upData_senstivity_Data", tempdata)
				// console.log(this.senstivity_Data)
			}

			this.ruleForm.WDCWASH2Num = this.senstivity_Data.WDCWASH2001.length
			if (this.ruleForm.WDCWASH2Num > 0) {
				this.ruleForm.WDCWASH2List = []
				for (
					let index = 0;
					index < parseInt(this.ruleForm.WDCWASH2Num);
					index++
				) {
					let n = index + 1
					this.ruleForm.WDCWASH2List.push({
						index: n.toString(),
						WDCWASH2001: this.senstivity_Data.WDCWASH2001[index],
					})
				}
				let tempdata = JSON.parse(JSON.stringify(this.senstivity_Data))
				tempdata.WDCWASH2Num = this.ruleForm.WDCWASH2Num
				this.$store.dispatch("upData_senstivity_Data", tempdata)
				// console.log(this.senstivity_Data)
			}
		},
		queryDetail() {
			// 查询明细
			// console.log(this.senstivity_Data)
		},
		handleClick() {},
		addWDCWASH1Num() {
			// console.log(this.ruleForm.WDCWASH1Num)
			this.ruleForm.WDCWASH1List = []
			for (
				let index = 1;
				index <= parseInt(this.ruleForm.WDCWASH1Num);
				index++
			) {
				this.ruleForm.WDCWASH1List.push({
					index: index.toString(),
					WDCWASH1001: "",
				})
			}
			let tempdata = JSON.parse(JSON.stringify(this.senstivity_Data))
			tempdata.WDCWASH1Num = this.ruleForm.WDCWASH1Num
			this.$store.dispatch("upData_senstivity_Data", tempdata)
			// console.log(this.senstivity_Data.only)
		},
		addWDCWASH2Num() {
			// console.log(this.ruleForm.WDCWASH2Num)
			this.ruleForm.WDCWASH2List = []
			for (
				let index = 1;
				index <= parseInt(this.ruleForm.WDCWASH2Num);
				index++
			) {
				this.ruleForm.WDCWASH2List.push({
					index: index.toString(),
					WDCWASH2001: "",
				})
			}
			let tempdata = JSON.parse(JSON.stringify(this.senstivity_Data))
			tempdata.WDCWASH2Num = this.ruleForm.WDCWASH2Num
			this.$store.dispatch("upData_senstivity_Data", tempdata)
			// console.log(this.senstivity_Data.only)
		},
		tijiao() {
			this.$refs.form.validate((valid) => {
				if (valid) {
					// console.log(this.senstivity_Data)
					let tempdata = JSON.parse(
						JSON.stringify(this.senstivity_Data)
					)
					let tempWDCWASH1001 = this.ruleForm.WDCWASH1List.map(
						(item) => {
							return parseFloat(item.WDCWASH1001)
								? parseFloat(item.WDCWASH1001)
								: 0
						}
					)
					tempdata.WDCWASH1001 = tempWDCWASH1001
					let tempWDCWASH2001 = this.ruleForm.WDCWASH2List.map(
						(item) => {
							return parseFloat(item.WDCWASH2001)
								? parseFloat(item.WDCWASH2001)
								: 0
						}
					)
					tempdata.WDCWASH2001 = tempWDCWASH2001
					// console.log(tempdata)
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "MINGAN",
						submitjson: JSON.stringify(tempdata),
					}
					// console.log(params)
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => {
							// console.log(res)
							var str = res.data.substring(0, 1)
							if (str == "E") {
								let message = res.data.substring(6)
								this.$notify.error({
									title: "提交失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "提交成功！",
									type: "success",
								})
								this.$router.go(-1)
							}
						})
						.catch((err) => {
							console.log(err)
						})
				}
			})
		},
		submitFun() {
			this.$refs.form.validate((valid) => {
				if (valid) { 
					let tempdata = JSON.parse(
						JSON.stringify(this.senstivity_Data)
					)
					let tempWDCWASH1001 = this.ruleForm.WDCWASH1List.map(
						(item) => {
							return parseFloat(item.WDCWASH1001)
								? parseFloat(item.WDCWASH1001)
								: 0
						}
					)
					tempdata.WDCWASH1001 = tempWDCWASH1001
					let tempWDCWASH2001 = this.ruleForm.WDCWASH2List.map(
						(item) => {
							return parseFloat(item.WDCWASH2001)
								? parseFloat(item.WDCWASH2001)
								: 0
						}
					)
					tempdata.WDCWASH2001 = tempWDCWASH2001
					// tempdata.SETPAGEINDEX = this.activeTab
					this.$store.dispatch("upData_senstivity_Data", tempdata) 
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "MINGAN",
						submitjson: JSON.stringify(tempdata),
					}
					// console.log(params)
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => {
							// console.log(res)
							var str = res.data.substring(0, 1)
							var message = res.data.substring(6)
							if (str == "E") {
								this.$notify.error({
									title: "提交失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "提交成功！",
									type: "success",
								})
							}
						})
						.catch((err) => {
							console.log(err)
						})
					this.$emit("changeActiveTab", this.activeTab)
					this.$store.dispatch(
						"change_senstivity_showTab",
						this.activeTab
					)
				}
			})
		},
	},
}
</script>
<style lang="scss" scoped>
.page-flex-row /deep/ .el-collapse-item__header {
	background: #f3f9fe;
}
</style>